//
//  RABookDetailBottomView.m
//  ReadApp
//
//  Created by 飞猪 on 2018/11/8.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "RABookDetailBottomView.h"
#import "JZLayoutButton.h"

@interface RABookDetailBottomView ()

@property (nonatomic, strong) JZLayoutButton *leftBtn;

@property (nonatomic, strong) JZLayoutButton *rightBtn;

@end


@implementation RABookDetailBottomView

#pragma mark - LifeCycle
- (instancetype)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    [self createViews];
  }
  return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
  self = [super initWithCoder:coder];
  if (self) {
    [self createViews];
  }
  return self;
}

- (void)layoutSubviews {
  [super layoutSubviews];
  
}

- (void)setJoinBookHidden {
  
  [self.rightBtn mas_updateConstraints:^(MASConstraintMaker *make) {
    make.width.mas_equalTo(self.mas_width);
  }];
  
}

#pragma mark - CreateViews
- (void)createViews {
  self.backgroundColor = [UIColor whiteColor];
  
  [self addSubview:self.leftBtn];
  [self addSubview:self.rightBtn];
  
  [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.bottom.left.mas_equalTo(0);
  }];
  
  [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.top.right.mas_equalTo(0);
    make.left.mas_equalTo(self.leftBtn.mas_right);
    make.width.mas_equalTo(self.leftBtn.mas_width);
  }];
  
}

- (void)clicked:(JZLayoutButton *)btn {
  
  if (self.delegate && [self.delegate respondsToSelector:@selector(bookDetailBottomView:type:)]) {
    [self.delegate bookDetailBottomView:self type:btn.tag];
  }
  
}

- (JZLayoutButton *)leftBtn {
  if (!_leftBtn) {
    _leftBtn = [JZLayoutButton buttonWithType:UIButtonTypeCustom];
    [_leftBtn setImage:[UIImage imageNamed:@"join_book"] forState:UIControlStateNormal];
    [_leftBtn setTitle:@"加入书架" forState:UIControlStateNormal];
    [_leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _leftBtn.layoutType = ZXGLayoutButtonTypeImageTopTitleBottom;
    _leftBtn.margin = 0.f;
    _leftBtn.tag = 0;
    _leftBtn.titleLabel.font = [UIFont systemFontOfSize:11.f];
    [_leftBtn setTitleColor:UIColorHex(666) forState:0];
    [_leftBtn addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
  }
  return _leftBtn;
}

- (JZLayoutButton *)rightBtn {
  if (!_rightBtn) {
    _rightBtn = [JZLayoutButton buttonWithType:UIButtonTypeCustom];
//    [_leftBtn setImage:[UIImage imageNamed:@"join_book"] forState:UIControlStateNormal];
    [_rightBtn setTitle:@"开始阅读" forState:UIControlStateNormal];
    [_rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    _rightBtn.layoutType = ZXGLayoutButtonTypeImageTopTitleBottom;
    _rightBtn.titleLabel.font = [UIFont systemFontOfSize:15.f];
    _rightBtn.backgroundColor = kMainColor;
    _rightBtn.tag = 1;
    [_rightBtn addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
  }
  return _rightBtn;
}

@end
